/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.cggveritas.crewintranet.jms.utils;

import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

/**
 *
 * @author Alassane
 */
@ManagedBean(name = "images")
@ApplicationScoped
public class Images implements Serializable {
    
//    private ImageService service;
//    /**
//     * Creates a new instance of Images
//     */
//    public Images() {
//
//    }
//
//    public StreamedContent getImage() throws IOException {
//        FacesContext context = FacesContext.getCurrentInstance();
//
//        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
//            // So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
//            return new DefaultStreamedContent();
//        } else {
//            // So, browser is requesting the image. Return a real StreamedContent with the image bytes.
//            String id = context.getExternalContext().getRequestParameterMap().get("id");
//            Image image = service.find(Long.valueOf(id));
//            return new DefaultStreamedContent(new ByteArrayInputStream(image.getBytes()));
//        }
//    }

}
